//
//  WHWelcomeViewController.swift
//  8.31-WH微博
//
//  Created by 吴涵 on 15/9/9.
//  Copyright © 2015年 wuhan. All rights reserved.
//

import UIKit
import SDWebImage
class WHWelcomeViewController: UIViewController {
    private var iconBottomCons: NSLayoutConstraint?

    override func viewDidLoad() {
        
      setUpUI()
        iconView.sd_setImageWithURL(UserAccountViewModel.sharedUserAccount.avatarUrl)
        print(UserAccountViewModel.sharedUserAccount.avatarUrl)
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        let h = -(UIScreen.mainScreen().bounds.height + iconBottomCons!.constant)
        iconBottomCons?.constant = h
        
        label.alpha = 0
        UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 10, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.8, animations: { () -> Void in
                    self.label.alpha = 1
                    }, completion: { (_) -> Void in
                        // TODO: -
                        NSNotificationCenter.defaultCenter().postNotificationName(WHSwithRootControllerNotification, object: nil)
                })
        }
    }
    
    private func setUpUI(){
    
        view.addSubview(backImageView)
        view.addSubview(iconView)
        view.addSubview(label)
        
        backImageView.ff_Fill(view)
        
        let cons = iconView.ff_AlignInner(type: ff_AlignType.BottomCenter, referView: view, size: CGSize(width: 90, height: 90), offset: CGPoint(x: 0, y: -200))
        self.iconBottomCons = iconView.ff_Constraint(cons, attribute: NSLayoutAttribute.Bottom)
        
        label.ff_AlignVertical(type: ff_AlignType.BottomCenter, referView: iconView, size: nil, offset: CGPoint(x: 0, y: 16))
//        backImageView.translatesAutoresizingMaskIntoConstraints = false
//        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-0-[v]-0-|", options: [], metrics: nil, views: ["v": backImageView]))
//        view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[v]-0-|", options: [], metrics: nil, views: ["v": backImageView]))
//
//        iconView.translatesAutoresizingMaskIntoConstraints = false
//        view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
//        view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: -200))
//        self.iconBottomCons = view.constraints.last
//        view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 90))
//        view.addConstraint(NSLayoutConstraint(item: iconView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 90))
//        
//        label.translatesAutoresizingMaskIntoConstraints = false
//        view.addConstraint(NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.Bottom, multiplier: 1.0, constant: 20))
//        view.addConstraint(NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.CenterX, relatedBy: NSLayoutRelation.Equal, toItem: iconView, attribute: NSLayoutAttribute.CenterX, multiplier: 1.0, constant: 0))
//    
    }
    private lazy var backImageView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    private lazy var iconView:UIImageView = {
    let view = UIImageView(image: UIImage(named: "avatar_default_big"))
        view.layer.cornerRadius = 45
        view.layer.masksToBounds = true
        return view
    }()
    private lazy var label: UILabel = UILabel(title: "我是妖怪", color: UIColor.blackColor(), fontSize: 18)
    
    
//    {
//    
//        let label = UILabel()
//        label.text = "怒吼吧兄弟"
//        label.textAlignment = NSTextAlignment.Center
//        return label
    
   // }()
}
